package com.thundersoft.pickcolor.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;

public class DatabaseHelper extends SQLiteOpenHelper {

    /**
     * 颜色表
     * id：颜色表唯一标识
     * hexValue：16进制
     * rValue：GRB的R
     * gValue：GRB的G
     * bValue：GRB的B
     * kind：分类（普通&收藏&搜索）
     */
    private static final String CREATE_COLOR = "create table Color(" +
            "id integer primary key autoincrement," +
            "hexValue text not null," +
            "rValue integer not null," +
            "gValue integer not null," +
            "bValue integer not null," +
            "kind text not null," +
            "describe text," +
            "userId integer)";

    private static final String CREATE_USER = "create table User(" +
            "id integer primary key autoincrement," +
            "name text not null," +
            "password text not null," +
            "sex text,"+
            "age integer," +
            "avatarName text)";


    private Context mContext;

    public DatabaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory,
                          int version) {
        super(context, name, factory, version);
        mContext = context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_COLOR);
        db.execSQL(CREATE_USER);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("drop table if exists Color");
        db.execSQL("drop table if exists User");
        onCreate(db);
    }
}
